define(['../../carrys/jsonList','../../../../js/lib/other/sweet-alert'],function(jsonData) {
    return ['$scope','$location', '$interval','$timeout','$routeParams', function($scope,$location,$interval,$timeout,$routeParams) {
    	$scope.$emit("top-show",'true');//顶部显示
    	$scope.$emit('menuTypeLight','loan'); 	//控制底部menu高亮
    	$scope.$emit('bub-menu','true'); 	//隐藏底部menu
    	$scope.$emit('flag-tag','3-4'); 	//显示底部文字
    	
    	//默认值
    	$scope.jsonList = jsonData;
    	$scope.creditorType = "";$scope.applicantType = "";$scope.idType = "";
    	
    	//赋值数据
    	if(bodyInfo.loanFormData != ""){
	    	$scope.applicantType = bodyInfo.loanFormData.applyUserType;
	    	$scope.applyName = bodyInfo.loanFormData.applyUserName;
	    	$scope.idType = bodyInfo.loanFormData.idType;
	    	$scope.documentsNo = bodyInfo.loanFormData.idNo;
	    	$scope.loanAmount = bodyInfo.loanFormData.loanAmount;
	    	$scope.creditorType = bodyInfo.loanFormData.debtType;
	    	$scope.caseNo = bodyInfo.loanFormData.caseNo;
	    	$scope.caseQuan = bodyInfo.loanFormData.caseAmount;
    	}
    	
    	//点击到下一步
    	$scope.goNext = function(){
    		if(! $scope.applicantType){
    			$scope.$emit("promptAlertMsg","申请人类别不能为空");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
                return;
    		}else if(! $scope.applyName){
    			$scope.$emit("promptAlertMsg","申请人不能为空");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
                return;
    		}else if(! $scope.idType){
    			$scope.$emit("promptAlertMsg","证件类别不能为空");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
                return;
    		}else if(! $scope.documentsNo){
    			$scope.$emit("promptAlertMsg","证件号码不能为空");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
                return;
    		}else if(isNaN($scope.loanAmount *1)){
    			$scope.$emit("promptAlertMsg","贷款金额格式不正确");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
                return;
    		}else{
    			if(!_YHC_util.IdentityCodeValid($scope.documentsNo) && $scope.idType === '1'){
    				$scope.$emit("promptAlertMsg","无效身份证号");
        			$scope.$emit("showCollect",true);
        			$timeout(function(){
        				$scope.$emit("showCollect",false);
        			},transData.promptTime);
                    return;
    			}else if( !_YHC_util.isValidBusCode($scope.documentsNo) && $scope.idType === '2'){
    				$scope.$emit("promptAlertMsg","无效营业执照号");
        			$scope.$emit("showCollect",true);
        			$timeout(function(){
        				$scope.$emit("showCollect",false);
        			},transData.promptTime);
                    return;
    			}else if( !_YHC_util.isValidOrgCode($scope.documentsNo) && $scope.idType === '3'){
    				$scope.$emit("promptAlertMsg","无效组织机构代码");
        			$scope.$emit("showCollect",true);
        			$timeout(function(){
        				$scope.$emit("showCollect",false);
        			},transData.promptTime);
                    return;
    			}else if($scope.loanAmount *1 > 10000000){
    				$scope.$emit("promptAlertMsg","贷款金额不得超过100万");
        			$scope.$emit("showCollect",true);
        			$timeout(function(){
        				$scope.$emit("showCollect",false);
        			},transData.promptTime);
                    return;
    			}else{
    				if($scope.caseQuan != "" && $scope.caseQuan != null && $scope.caseQuan != 'undefined'){
    					if(isNaN($scope.caseQuan *1)){
    		    			$scope.$emit("promptAlertMsg","涉案金额格式不正确");
    		    			$scope.$emit("showCollect",true);
    		    			$timeout(function(){
    		    				$scope.$emit("showCollect",false);
    		    			},transData.promptTime);
    		                return;
    		    		}else{
    		    			saveData();
    		    		}
    				}else{
    					saveData();
    				}
    			}
    		}
    	}
    	
    	
    	//保存数据
    	function saveData(){
    		var tempData = {};
    		tempData.inviteCode = $routeParams.flag;
    		tempData.applyUserType = ($scope.applicantType == "" || $scope.applicantType == null)?"":$scope.applicantType;
    		tempData.applyUserName = $scope.applyName;
    		tempData.idType = ($scope.idType == "" || $scope.idType == null)?"": $scope.idType;
    		tempData.idNo = $scope.documentsNo;
    		tempData.loanAmount = $scope.loanAmount;
    		tempData.debtType = ($scope.creditorType == "" || $scope.creditorType == null)?"":$scope.creditorType;
    		tempData.caseNo = $scope.caseNo;
    		tempData.caseAmount = $scope.caseQuan;
    		bodyInfo.loanFormData = tempData;
    		$scope.$emit("goNext","/noticeUpload");
    	}
    	
        $scope.$apply();
    }];
});